<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <style>
    .red{
      background:red;
    }
  </style>
  <script src="js/vue.js"></script>
  <script src="js/vue-resource.js"></script>
  <script>
    window.onload=function(){
      new Vue({
        el:"#box",
        data :{
          datas :[],
          search : "",
          now : -1
        },
        methods:{
          get:function(event){
            if(event.keyCode==38 || event.keyCode==40) return;
            if(event.keyCode == 13){
              window.open('https://www.baidu.com/s?wd='+this.search);
              this.search = "";
            }
            this.$http.jsonp("https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su",{
              wd:this.search
            },{
              jsonp:"cb"
            }).then(function(result){
              this.datas = result.data.s
            },function(result){

            })
          },
          changeDown:function(){
            this.now ++;
            if(this.now == this.datas.length) this.now = -1;
            this.search = this.datas[this.now]
          },
          changeUp:function(){
            this.now --;
            if(this.now == -2) this.now = this.datas.length -1;
            this.search = this.datas[this.now]
          }
        }
      })
    }
  </script>
</head>
<body>
<div id="box">
  <input type="text" v-model="search" @keyup="get($event)" @keydown.down="changeDown" @keydown.up.prevent="changeUp">
  <ul>
    <li v-for="data in datas" :class="{red:now ===$index}">{{data}}</li>
  </ul>
  <p v-show="datas.length <= 0">暂无数据----</p>
</div>
</body>
</html>